From 8cf53bca9c4dbf2450894eaf463f9bba67df83fc Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sat, 14 Apr 2018 11:44:42 +0200 Subject: [PATCH] Move more input validation into BuildConfig::new() --- src/cargo/core/compiler/mod.rs | 16 +++++++++++++++- src/cargo/ops/cargo_compile.rs | 20 ++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 031321faf..498e594cd 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -82,7 +82,18 @@ impl BuildConfig { rustc_info_cache: Option, mode: CompileMode, ) -> CargoResult { - if let &Some(ref s) = requested_target { + let requested_target = match requested_target { + &Some(ref target) if target.ends_with(".json") => { + let path = Path::new(target) + .canonicalize() + .chain_err(|| format_err!("Target path {:?} is not a valid file", target))?; + Some(path.into_os_string() + .into_string() + .map_err(|_| format_err!("Target path is not valid unicode"))?) + } + other => other.clone(), + }; + if let Some(ref s) = requested_target { if s.trim().is_empty() { bail!("target was empty") } @@ -90,6 +101,9 @@ impl BuildConfig { let cfg_target = config.get_string("build.target")?.map(|s| s.val); let target = requested_target.clone().or(cfg_target); + if jobs == Some(0) { + bail!("jobs must be at least 1") + } if jobs.is_some() && config.jobserver_from_env().is_some() { config.shell().warn( "a `-j` argument was passed to Cargo but Cargo is \ diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 0abad64f0..ec031b526 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -23,7 +23,7 @@ //! use std::collections::HashSet; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::sync::Arc; use core::compiler::{BuildConfig, BuildContext, Compilation, Context, DefaultExecutor, Executor}; @@ -34,7 +34,7 @@ use core::{Package, Source, Target}; use core::{PackageId, PackageIdSpec, TargetKind, Workspace}; use ops; use util::config::Config; -use util::{lev_distance, profile, CargoResult, CargoResultExt}; +use util::{lev_distance, profile, CargoResult}; /// Contains information about how a package should be compiled. #[derive(Debug)] @@ -229,22 +229,6 @@ pub fn compile_ws<'a>( ref export_dir, } = *options; - let target = match target { - &Some(ref target) if target.ends_with(".json") => { - let path = Path::new(target) - .canonicalize() - .chain_err(|| format_err!("Target path {:?} is not a valid file", target))?; - Some(path.into_os_string() - .into_string() - .map_err(|_| format_err!("Target path is not valid unicode"))?) - } - other => other.clone(), - }; - - if jobs == Some(0) { - bail!("jobs must be at least 1") - } - let rustc_info_cache = ws.target_dir() .join(".rustc_info.json") .into_path_unlocked(); -- 2.30.2